﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using AssetManageSystem.Model.AssetManage;


namespace AssetManageSystem.ViewModel.AssetManage.AssetDonationVMs
{
    public partial class AssetDonationListVM : BasePagedListVM<AssetDonation_View, AssetDonationSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("AssetDonation", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-green"),
                this.MakeStandardAction("AssetDonation", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-blue"),
                this.MakeStandardAction("AssetDonation", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-red"),
                this.MakeStandardAction("AssetDonation", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "AssetManage", dialogWidth: 800).SetButtonClass("btn-col-8"),
                // this.MakeStandardAction("AssetDonation", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-orange"),
                this.MakeStandardAction("AssetDonation", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-red"),
                // this.MakeStandardAction("AssetDonation", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "AssetManage", dialogWidth: 800).SetButtonClass("btn-col-4"),
                this.MakeStandardAction("AssetDonation", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "AssetManage").SetButtonClass("btn-col-4"),
            };
        }


        protected override IEnumerable<IGridColumn<AssetDonation_View>> InitGridHeader()
        {
            return new List<GridColumn<AssetDonation_View>>{
                this.MakeGridHeader(x => x.DocNumber),
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Unit),
                this.MakeGridHeader(x => x.OutDate),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<AssetDonation_View> GetSearchQuery()
        {
            var query = DC.Set<AssetDonation>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Unit, x=>x.Unit)
                .CheckBetween(Searcher.OutDate?.GetStartTime(), Searcher.OutDate?.GetEndTime(), x => x.OutDate, includeMax: false)
                .CheckWhere(Searcher.SelectedAssetIdIDs,x=>DC.Set<AssetDonationMiddleTable>().Where(y=>Searcher.SelectedAssetIdIDs.Contains(y.AssetId)).Select(z=>z.AssetDonationId).Contains(x.ID))
                .Select(x => new AssetDonation_View
                {
				    ID = x.ID,
                    DocNumber = x.DocNumber,
                    Name = x.Name,
                    Unit = x.Unit,
                    OutDate = x.OutDate,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class AssetDonation_View : AssetDonation{

    }
}
